﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DBHelper
{
    /// <summary>
    /// 自定义属性,用于指示如何从DataTable或者DbDataReader中读取类的属性值
    /// </summary>
    public class ColumnAttribute : Attribute
    {
        /// <summary>
        /// 类属性对应的列名
        /// </summary>
        public string ColumnName { get; set; }
        /// <summary>
        /// 此列是否允许为空
        /// </summary>
        public bool Nullable { get; set; }
        /// <summary>
        /// 此列默认值,仅当列允许为空时且未指定其值时才会考虑默认值
        /// </summary>
        public object DefaultValue { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="columnName">类属性对应的列名</param>
        public ColumnAttribute(string columnName)
        {
            ColumnName = columnName;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="columnName">类属性对应的列名</param>
        /// <param name="nullable">此列是否允许为空</param>
        public ColumnAttribute(string columnName,bool nullable)
        {
            ColumnName = columnName;
            Nullable = nullable;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="columnName">类属性对应的列名</param>
        /// <param name="nullable">此列是否允许为空</param>
        /// <param name="defaultValue">此列默认值,仅当列允许为空时且未指定其值时才会考虑默认值</param>
        public ColumnAttribute(string columnName, bool nullable,object defaultValue)
        {
            ColumnName = columnName;
            Nullable = nullable;
            DefaultValue = defaultValue;
        }
    }
}
